home *** CD-ROM | disk | FTP | other *** search
/ PC World Komputer 2010 April / PCWorld0410.iso / pluginy Firefox / 4810 / 4810.xpi / chrome / speeddial.jar / content / editPluginDial.js < prev    next >
Text File  |  2010-01-31  |  5KB  |  121 lines

  1. // Global vars
  2. var gPref = Components.classes["@mozilla.org/preferences-service;1"]
  3.                .getService(Components.interfaces.nsIPrefService)
  4.                .QueryInterface(Components.interfaces.nsIPrefBranch2);
  5. var targetDial = -1;
  6. var retVals = null;
  7.  
  8. var PLUGIN_GADGET = 0;
  9. var PLUGIN_CUSTOM = 1;
  10.  
  11. function Startup() {
  12.   // Set variables
  13.   targetDial = window.arguments[0];
  14.   //retVals = window.arguments[1];
  15.  
  16.   var speedDialBundle = document.getElementById("bundle_speeddial");
  17.  
  18.   var defaultTab = PLUGIN_GADGET;
  19.   
  20.   if (gPref.prefHasUserValue("extensions.speeddial.thumbnail-" + targetDial + "-url")) {
  21.     var targetURL = gPref.getCharPref("extensions.speeddial.thumbnail-" + targetDial + "-url");
  22.     if (SpeedDialUtils.stringStartsWith(targetURL, "plugin:")) {
  23.       defaultTab = PLUGIN_CUSTOM;
  24.       document.getElementById("url").value = targetURL.substr("plugin:".length);
  25.     }
  26.     if (SpeedDialUtils.stringStartsWith(targetURL, "plugin:http://www.gmodules.com/ig/ifr")) {
  27.       defaultTab = PLUGIN_GADGET;
  28.       document.getElementById("currentGadget").value = targetURL.substr("plugin:".length);
  29.     }
  30.   }
  31.   
  32.   document.getElementById("pluginTypes").selectedIndex = defaultTab;
  33. }
  34.  
  35. function onOK(event) {
  36.   var speedDialBundle = document.getElementById("bundle_speeddial");
  37.   
  38.   var currentTab = document.getElementById("pluginTypes").selectedIndex;
  39.   
  40.   if (currentTab == PLUGIN_GADGET) {
  41.     var newGadget = document.getElementById("newGadget").value;
  42.     var reScript = new RegExp("<script src=\"(.*)\"></script>");
  43.     var resultsScript = reScript.exec(newGadget);
  44.     if ((resultsScript) && (resultsScript[1]) && (resultsScript[1] != '')) {
  45.       SpeedDialUtils.deassignThumbnail(targetDial);
  46.       var gadgetURL = resultsScript[1].replace(/&/g, "&");
  47.       gadgetURL = gadgetURL.replace("&output=js", "&output=html");
  48.       gPref.setCharPref("extensions.speeddial.thumbnail-" + targetDial + "-url", "plugin:" + gadgetURL);
  49.       var reTitle = new RegExp("&title=(.*)&");
  50.       var resultsTitle = reTitle.exec(gadgetURL);
  51.       if ((resultsTitle) && (resultsTitle[1]) && (resultsTitle[1] != '')) {
  52.         var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  53.         str.data = resultsTitle[1];
  54.         gPref.setComplexValue("extensions.speeddial.thumbnail-" + targetDial + "-label", Components.interfaces.nsISupportsString, str);
  55.       } else {
  56.         gPref.setBoolPref("extensions.speeddial.thumbnail-" + targetDial + "-dynamictitle", true);
  57.         var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  58.         str.data = "";
  59.         gPref.setComplexValue("extensions.speeddial.thumbnail-" + targetDial + "-label", Components.interfaces.nsISupportsString, str);
  60.       }
  61.       if (SpeedDialUtils.isFirefox3()) {
  62.         gPref.setCharPref("extensions.speeddial.thumbnail-" + targetDial + "-icon", "data:");
  63.       }
  64.     } else {
  65.       var promptService = Components.classes['@mozilla.org/embedcomp/prompt-service;1'].getService(Components.interfaces.nsIPromptService);
  66.       promptService.alert(window, 
  67.         speedDialBundle.getString("gadget.badformattitle"), 
  68.         speedDialBundle.getString("gadget.badformat"));
  69.       return false;
  70.     }
  71.  
  72.   } else if (currentTab == PLUGIN_CUSTOM) {
  73.     SpeedDialUtils.deassignThumbnail(targetDial);
  74.     gPref.setCharPref("extensions.speeddial.thumbnail-" + targetDial + "-url", "plugin:" + document.getElementById("url").value);
  75.     gPref.setBoolPref("extensions.speeddial.thumbnail-" + targetDial + "-dynamictitle", true);
  76.     var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
  77.     str.data = "";
  78.     gPref.setComplexValue("extensions.speeddial.thumbnail-" + targetDial + "-label", Components.interfaces.nsISupportsString, str);
  79.     if (SpeedDialUtils.isFirefox3()) {
  80.       gPref.setCharPref("extensions.speeddial.thumbnail-" + targetDial + "-icon", "data:");
  81.     }
  82.   }
  83.   
  84.   
  85.   return true;
  86. }
  87.  
  88. function onCancel(event) {
  89.   if (retVals != null) {
  90.     retVals.canceled = true;
  91.   }
  92.   return true;
  93. }
  94.  
  95. function openFullEdit() {
  96.   window.opener.openDialog("chrome://speeddial/content/editDial.xul", "",
  97.              "centerscreen,chrome,dialog,resizable,dependent",
  98.              targetDial);
  99.   window.close();
  100. }
  101.  
  102. function openURL(aURL)
  103. {
  104.    if (aURL == null) aURL = "about:blank";
  105.    
  106.    var windowManager = Components.classes["@mozilla.org/appshell/window-mediator;1"]
  107.            .getService(Components.interfaces.nsIWindowMediator);
  108.  
  109.    // check for an existing window and focus it; it's not application modal
  110.    var anyWindow = windowManager.getMostRecentWindow("navigator:browser");
  111.  
  112.    if (!anyWindow) {
  113.      var hiddenWin = Components.classes[ "@mozilla.org/appshell/appShellService;1" ].
  114.         getService(Components.interfaces.nsIAppShellService).
  115.         hiddenDOMWindow;
  116.      hiddenWin.open(aURL, "_blank");
  117.    } else {
  118.      anyWindow.open(aURL, "_blank");
  119.    }
  120. }
  121.